package com.cs.peanut.player.api;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by peanut on 2018/05/16.
 */

public class Api {
    private static Api _instance = null;
    private static ApiService apiService = null;
    private Api (){

    }

    private static ApiService getApiService(String ip){
        if(apiService == null) {
            apiService = new Retrofit.Builder()
                    .baseUrl(Constants.ServerConfig.url(ip))
                    .addConverterFactory(GsonConverterFactory.create()).build().create(ApiService.class);
        }
        return apiService;
    }

    public static synchronized ApiService get(String ip){
        if(_instance == null){
            _instance = new Api();
        }
        return _instance.getApiService(ip);
    }
}
